<?php
/**
* 这是题库
*/
class ControllerTiku extends GetLoad
{
	

	public function index(){

		$this->load("Model/tiku");
		$this->load("Model/name");
		$namezhuan=new Modelnamezhuanhua();
		$tiku=new ModelTiku();
		$name_id=$namezhuan->getname($_COOKIE['name'])['name_id'];
		$liebiao=$tiku->qutikumulu($name_id);

		foreach ($liebiao as $lie) {

			$data['mulu'][] = array(
				'id' =>$lie['id'] , 
				'name'=>$lie['name']
			);
			
		}
		//var_dump($data);
		$this->view("view/tiku",$data);


	}

	public function qutiku($jieshou){
		$juanzi=$jieshou[0];
		$this->load("Model/tiku");
		$this->load("Model/name");
		$namezhuan=new Modelnamezhuanhua();
		$tiku=new ModelTiku();
		$name_id=$namezhuan->getname($_COOKIE['name'])['name_id'];
		if($tiku->yanzheng($name_id,$juanzi)){
			$qutiku=$tiku->qutiku($juanzi);
			foreach ($qutiku as $ti) {
				$data['shijuan'][] = array(
					'timu' =>$ti['timu'] , 
					'a' => $ti['a'], 
					'b' =>$ti['b'], 
					'c' => $ti['c'], 
					'd' => $ti['d'], 
					'daan' =>$ti['daan'], 
					'y' =>$ti['y'], 
					'n' =>$ti['n']
				);
			}
			$this->view("view/shijuan",$data);

		}



	}

	public function gettiku($jieshou){
		$data["laoshi_id"]=$jieshou[0];


		$this->load("Model/xuesheng");
		
		$this->load("Model/tiku");
		$this->load("Model/name");


		$xuesheng=new ModelXuesheng();
		$namezhuan=new Modelnamezhuanhua();
		$tiku=new ModelTiku();


		$name_id=$namezhuan->getname($_COOKIE['name'])['name_id'];
		$class_id=$namezhuan->getname($_COOKIE['name'])['class'];
		//echo $class_id;
	

		if($namezhuan->yanzheng1()){


 
				$reluse=$xuesheng->Getlaoshime($class_id);


				foreach ($reluse as  $value) {
					$data['laoshi'][] = array(
						'id'   =>$value['laoshi_id'] ,
						'name' =>$namezhuan->getname_id($value['laoshi_id'])['name']
						 );
					
				}

				
				if($data['laoshi_id']!=0){
					$data['mulu']=$tiku->qutikumulu($data["laoshi_id"]);
					//var_dump($data);
				}



				$this->view("view/gettiku",$data);




		}else{
			header("Location: ./index.php?route=Controller/denglu/ControllerDenglu/denglu"); 
		}

	}

	public function shengchengshijuan($jieshou){

		$juanzi_id=$jieshou[0];
		$data['shijuan_id']=$juanzi_id;




		
		$this->load("Model/tiku");
		$this->load("Model/name");


		$namezhuan=new Modelnamezhuanhua();
		$tiku=new ModelTiku();

		$name_id=$namezhuan->getname($_COOKIE['name'])['name_id'];
		$class_id=$namezhuan->getname($_COOKIE['name'])['class'];
		$data['shijuanming']=$tiku->getmingzi($juanzi_id);

		$neirong=$tiku->qutiku($juanzi_id);
		foreach ($neirong as $ti) {
				$data['shijuan'][] = array(
					'id'   =>$ti['timu_id'] , 
					'timu' =>$ti['timu'] , 
					'a'    =>$ti['a'], 
					'b'    =>$ti['b'], 
					'c'    =>$ti['c'], 
					'd'    =>$ti['d'], 
					'y'    =>$ti['y'], 
					'n'    =>$ti['n']
				);
			}
		$this->view("view/shengchengshijuan",$data);







	}

	public function panjuan($jieshou){

		$juanzi_id=$jieshou[0];

		$this->load("Model/tiku");
		$this->load("Model/name");


		$namezhuan=new Modelnamezhuanhua();
		$tiku=new ModelTiku();

		$name_id=$namezhuan->getname($_COOKIE['name'])['name_id'];
		$class_id=$namezhuan->getname($_COOKIE['name'])['class'];
		$data['shijuanming']=$tiku->getmingzi($juanzi_id);

		if($tiku->panduandati($name_id,$juanzi_id)){


		
			$neirong=$tiku->qutiku($juanzi_id);
			$i=0;
			foreach ($neirong as $ti) {
					if($_POST[$ti['timu_id']]==$ti['daan']){
						$tiku->duicuojiu($ti['timu_id'],1,0);
						$i++;
						
					}else{

						$tiku->duicuojiu($ti['timu_id'],0,1);



					}
			}

			$tiku->jiluchengji($name_id,$juanzi_id,$i);
			echo "您考了".$i."分";

		}else{
			echo "您已经参与答题，不会为您记录和显示成绩 <a herf='./index'>点击返回主页</a>";
		}

		

	}

	public function quchengji(){


		$this->load("Model/tiku");
		$this->load("Model/name");
		$namezhuan=new Modelnamezhuanhua();
		$tiku=new ModelTiku();
		$name_id=$namezhuan->getname($_COOKIE['name'])['name_id'];
		$liebiao=$tiku->qutikumulu($name_id);

		foreach ($liebiao as $lie) {

			$data['mulu'][] = array(
				'id' =>$lie['id'] , 
				'name'=>$lie['name']
			);
			
		}
		//var_dump($data);
		$this->view("view/tiku2",$data);
	}

	public function chengji($jieshou){
		$juanzhi_id=$jieshou[0];
		$this->load("Model/tiku");
		$this->load("Model/name");
		$namezhuan=new Modelnamezhuanhua();
		$tiku=new ModelTiku();
		$name_id=$namezhuan->getname($_COOKIE['name'])['name_id'];
		$chengjis=$tiku->quchengji($juanzhi_id);
		foreach ($chengjis as $chengji) {
			$data['chengji'][] = array(
				'name'   =>$namezhuan->getname_id($chengji["name_id"])['name'], 
				'fenshu' =>$chengji['chengji']
			);
			
		}

		$this->view("view/fenshu",$data);


	}

	
}